<template>
  <div >
    <!-- 基本信息 -->
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">前向合同信息</span>
    </div>
    <van-field readonly required name="contractCode" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].contractCode" label="合同编码：" label-width="5em" />
    <van-field readonly required name="contractName" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].contractName" label="合同名称：" label-width="5em" autosize rows="1" type="textarea"/>
    <van-field readonly required name="contractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].contractAmount" label="合同总金额(含税,元)：" label-width="11.25em" />
    <van-field readonly required name="nineOneFlag" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].nineOneFlag=='Y'?'是':'否'" label="是否含9One平台收入：" label-width="11em" />
    <van-field readonly required name="nineOneContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].nineOneContractAmount" label="9One平台能力合同总金额(含税,元)：" label-width="17em" />
    <van-field readonly name="specialContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].specialContractAmount" label="专线产品合同金额(含税,元)：" label-width="14em" />
    <van-field readonly required name="securityFlag" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].securityFlag=='Y'?'是':'否'" label="是否含安全赛道收入：" label-width="10em" />
    <van-field readonly required name="securityProductContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].securityProductContractAmount" label="安全赛道产品合同总金额(含税,元)：" label-width="16em" />
    <van-field readonly name="internetContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].internetContractAmount" label="物联网产品合同金额(含税,元)：" label-width="14em" />
    <van-field readonly required name="aiFlag" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].aiFlag=='Y'?'是':'否'" label="是否含AI能力收入：" label-width="9.5em" />
    <van-field readonly name="aiContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].aiContractAmount" label="AI能力合同总金额(含税,元)：" label-width="15em" />
    <van-field readonly name="yiDongCloudContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].yiDongCloudContractAmount" label="移动云产品合同金额(含税,元)：" label-width="14em" />
    <van-field readonly name="ortherProductContractAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].ortherProductContractAmount" label="其它标准产品合同金额(含税,元)：" label-width="15em" />
    <van-field readonly required name="solutionInfoBudgeAmountN" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].solutionInfoBudgeAmountN" label="三化解决方案收入预算金额(含税,元)：" label-width="17em" />
    <van-field readonly required name="billingAmount" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].billingAmount" label="含税累计出账金额(含税,元)：" label-width="13em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">后向合同信息</span>
    </div>
    <van-field readonly required name="afterContractCode" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].afterContractCode" label="三化复制后向合同编码：" label-width="11em" />
    <van-field readonly required name="afterContractName" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].afterContractName" label="三化复制后向合同名称：" label-width="11em"  autosize rows="1" type="textarea"/>
    <van-field readonly required name="contractCode" :value="fromdata.solutionIncentiveInfo.beforContractInfos[0].contractCode" label="客户前向合同编码：" label-width="9em" />
    <van-field readonly required name="groupProjectCode" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].groupProjectCode" label="ICT全网统一项目编码：" label-width="11.25em" />
    <van-field readonly required name="firstCompanyName" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].firstCompanyName" label="甲方名称(引入合同甲方全称)：" label-width="12em" autosize rows="1" type="textarea"/>
    <van-field readonly required name="firstCompanyProvinceCode" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].firstCompanyProvinceCode" label="甲方省份(引入省)：" label-width="9.5em" />
    <van-field readonly required name="firstCompanyCityCode" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].firstCompanyCityCode" label="甲方地市（引入地市）：" label-width="11em" />
    <van-field readonly required name="sencondCompanyName" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].sencondCompanyName" label="乙方揭榜单位(揭榜省/专业公司)：" label-width="12em" autosize rows="1" type="textarea"/>
    <van-field readonly required name="signingTime" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].signingTime" label="签订时间：" label-width="5em" />
    <van-field readonly required name="afterContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].afterContractAmount" label="与揭榜省签订的跨省后向合同金额(含税,元)：" label-width="12em" />
    <van-field readonly required name="solutionIncomeShare" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionIncomeShare" label="三化方案收入在项目签约金额占比(%)：" label-width="18em" />
    <van-field readonly required name="nineOneFlag" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].nineOneFlag=='Y'?'是':'否'" label="是否含9One平台收入：" label-width="11em" />
    <van-field readonly required name="nineOneContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].nineOneContractAmount" label="9One平台能力合同总金额(含税,元)：" label-width="17em" />
    <van-field readonly required name="securityTrackProductFlag" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].securityTrackProductFlag=='Y'?'是':'否'" label="是否含安全赛道收入：" label-width="10em" />
    <van-field readonly required name="securityProductContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].securityProductContractAmount" label="安全赛道产品合同拆分金额(含税,元)：" label-width="17em" />
    <van-field readonly name="specialContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].specialContractAmount" label="专线产品合同拆分金额(含税,元)：" label-width="15em" />
    <van-field readonly required name="aiFlag" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].aiFlag=='Y'?'是':'否'" label="是否含AI能力收入：" label-width="9.5em" />
    <van-field readonly required name="aiBusinessProductContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].aiBusinessProductContractAmount" label="AI能力合同拆分金额(含税,元)：" label-width="14em" />
    <van-field readonly name="internetContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].internetContractAmount" label="物联网产品合同拆分金额(含税,元)：" label-width="16em" />
    <van-field readonly name="mobileCloudContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].mobileCloudContractAmount" label="移动云产品合同拆分金额(含税,元)：" label-width="16em" />
    <van-field readonly name="ortherProductContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].ortherProductContractAmount" label="其它标准产品合同拆分金额(含税,元)：" label-width="17em" />
    <van-field readonly required name="hardwareContractAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].hardwareContractAmount" label="设备硬件合同拆分金额(含税,元)：" label-width="15em" />
    <van-field readonly required name="solutionNpvr" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionNpvr" label="三化方案净现值率(%)(效益评估)：" label-width="15.5em" />
    <van-field readonly required name="solutionProfitAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionProfitAmount" label="三化方案利润金额(含税,元)：" label-width="13em" />
    <van-field readonly required name="solutionProfitRate" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionProfitRate" label="三化方案利润率(%)(效益评估)：" label-width="14.5em" />
    <van-field readonly required name="solutionBudgetItTfProfitAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionBudgetItTfProfitAmount" label="三化方案IT通服利润金额(含税,元)：" label-width="16em" />
    <van-field readonly required name="solutionBudgetItTfSignAmount" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionBudgetItTfSignAmount" label="三化方案IT通服签约金额(含税,元)：" label-width="16em" />
    <van-field readonly required name="solutionBudgetItTfProfitMargin" :value="fromdata.solutionIncentiveInfo.afterContractInfos[0].solutionBudgetItTfProfitMargin" label="三化方案IT通服利润率(%)(效益评估)：" label-width="17.5em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">后向订单信息</span>
    </div>
    <van-field readonly required name="orderType" :value="fromdata.solutionIncentiveInfo.afterOrders[0].orderType=='1'?'能力中台订单':fromdata.solutionIncentiveInfo.afterOrders[0].orderType=='2'?'CMIOT平台订单':fromdata.solutionIncentiveInfo.afterOrders[0].orderType=='3'?'集客大厅':fromdata.solutionIncentiveInfo.afterOrders[0].orderType=='99'?'其他':''" label="订单类型：" label-width="5em" />
    <van-field readonly required name="orderNum" :value="fromdata.solutionIncentiveInfo.afterOrders[0].orderNum" label="订单编号：" label-width="5em" />
    <van-field readonly required name="orderAmount" :value="fromdata.solutionIncentiveInfo.afterOrders[0].orderAmount" label="订单金额(含税,元)：" label-width="9em" />
    <van-field readonly required name="hardwareContractAmount" :value="fromdata.solutionIncentiveInfo.afterOrders[0].hardwareContractAmount" label="设备硬件合同拆分金额(含税,元)：" label-width="15em" />
    <van-field readonly required name="firstCompanyCityCode" :value="fromdata.solutionIncentiveInfo.afterOrders[0].firstCompanyCityCode" label="甲方省份(引入省)：" label-width="9em" />
    <van-field readonly required name="sencondCompanyName" :value="fromdata.solutionIncentiveInfo.afterOrders[0].sencondCompanyName" label="乙方揭榜单位(揭榜省/专业公司)：" label-width="12em" autosize rows="1" type="textarea"/>
    <van-field readonly required name="orderTime" :value="fromdata.solutionIncentiveInfo.afterOrders[0].orderTime" label="订单时间：" label-width="5em" />
    <van-field readonly autosize type="textarea" rows="1" name="remark" :value="fromdata.solutionIncentiveInfo.afterOrders[0].remark" label="备注：" label-width="3em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">三化激励金额</span>
    </div>
    <van-field readonly required name="solutionCostExclusionIncentiveAmount" :value="fromdata.solutionIncentiveInfo.solutionIncentiveAmountInfo.solutionCostExclusionIncentiveAmount" label="三化专项成本激励金额(元)：" label-width="13em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">特殊情况说明</span>
    </div>
    <van-field readonly name="professionalCompanyAndCustomerFlag" :value="fromdata.solutionIncentiveInfo.specialInfo.professionalCompanyAndCustomerFlag=='Y'?'是':'否'" label="是否专业公司代表引入省与客户签约：" label-width="17em" />
    <van-field readonly name="professionalCompanyAndCompanyFlag" :value="fromdata.solutionIncentiveInfo.specialInfo.professionalCompanyAndCompanyFlag=='Y'?'是':'否'" label="是否专业公司代表引入省与揭榜单位签约：" label-width="19em" />
    <van-field readonly name="professionalCompany" :value="fromdata.solutionIncentiveInfo.specialInfo.professionalCompany" label="专业公司名称：" label-width="7em" />
    <van-field readonly name="professionalContractCode" :value="fromdata.solutionIncentiveInfo.specialInfo.professionalContractCode" label="专业公司客户合同编码：" label-width="11em" />
    <van-field readonly autosize type="textarea" rows="1" name="explain" :value="fromdata.solutionIncentiveInfo.specialInfo.explain" label="情况说明：" label-width="5em" />
    <van-field readonly autosize type="textarea" rows="1" name="orther" :value="fromdata.solutionIncentiveInfo.specialInfo.orther" label="其他：" label-width="3em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">激励申报附件</span>
    </div>
    <van-field readonly required label-width="12em" label="合同扫描件：" />
    <div v-for="(fileitem) in fromdata.fileListInfo.keyInformationFileList" :key="fileitem.id" style="margin-left:20px">
      <div readonly class="font14 fileLink" style="color:#0F85CF">
        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
      </div>
    </div>
    <van-field readonly required label-width="12em" label="报送确认函：" />
    <div v-for="(fileitem) in fromdata.fileListInfo.submitConfirmFileList" :key="fileitem.id" style="margin-left:20px">
      <div readonly class="font14 fileLink" style="color:#0F85CF">
        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
      </div>
    </div>
    <van-field readonly required label-width="12em" label="本次报送项目清单：" />
    <div v-for="(fileitem) in fromdata.fileListInfo.projectFileList" :key="fileitem.id" style="margin-left:20px">
      <div readonly class="font14 fileLink" style="color:#0F85CF">
        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
      </div>
    </div>
    <van-field readonly required label-width="12em" label="特殊情况核定说明：" />
    <div v-for="(fileitem) in fromdata.fileListInfo.exceptionalCaseFileList" :key="fileitem.id" style="margin-left:20px">
      <div readonly class="font14 fileLink" style="color:#0F85CF">
        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
      </div>
    </div>
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">激励审核
    </span>
    </div>
    <van-field readonly name="isArrears" :value="arrearageManagement.isArrears" label="是否存在欠费：" label-width="7em" />
    <van-field readonly name="arrearsAmount" :value="arrearageManagement.arrearsAmount" label="欠费金额(元)：" label-width="7.5em" />
    <van-field readonly name="isRiskWarn" :value="arrearageManagement.isRiskWarn" label="是否触发风险：" label-width="7em" />
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">赛道核定结果
    </span>
    </div>
    <el-table :data="fromdata.approvalInfo.incentiveVerifiedInfo" border style="width: 100%">
      <el-table-column prop="incentiveName" label="激励类型" width="120"/>
      <el-table-column prop="autodromeName" label="赛道名称" width="120"/>
      <el-table-column label="核定结果" width="120">
        <template slot-scope="scope">
          <div @click="canSelete?showPopupView(scope.$index):null" v-if="scope.row.resultFlag=='Y'">同意</div>
          <div @click="canSelete?showPopupView(scope.$index):null" v-else>不同意</div>
        </template>
      </el-table-column>
    </el-table>
    <van-field :readonly="!canSelete" required autosize type="textarea" rows="1" name="remark" v-model="fromdata.approvalInfo.remark" label="审核工单处理意见：" label-width="9em" :is-link="canSelete"/>
    <van-field readonly label-width="12em" label="审核附件：">
<!--      <template #button v-if="canSelete">-->
<!--        <van-uploader :after-read="file2server">-->
<!--          <van-button size="small" type="primary" color="#0f85cf">上传附件</van-button>-->
<!--        </van-uploader>-->
<!--      </template>-->
    </van-field>
    <div v-for="(fileitem,index) in fromdata.approvalInfo.opinionFileList" :key="fileitem.id" style="margin-left:20px">
      <div readonly class="font14 fileLink" style="color:#0F85CF">
        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
      </div>
<!--      <van-icon v-if="canSelete" name="close" color="#ea0023" size="20" @click="deleteFile(index)" />-->
    </div>
    <van-popup v-model="isshowPopupView" position="bottom" get-container="body">
      <van-picker show-toolbar :value-key="'label'" :columns="isPmoPopupColumns" @confirm="isPmoClickConfirm" @cancel="isshowPopupView = false" />
    </van-popup>
    <div style="margin-bottom: 50px"></div>
  </div>
</template>
<script>
import { mapGetters } from "vuex"
import {
  existArrearsAndRiskWarning,
  getCountyCode,
  getProductNameAndProductCode,
  queryTrack,
  uploadFileCommon
} from "@/api/dictapi";
import {Dialog, Notify} from "vant";
import {openFileUrl} from "@/store/openFile";

export default {
  data() {
    return {
      approvalInfo:{},
      arrearageManagement:{},
      nineOneName:'',
      canSelete:false,
      isshowPopupView:false,
      isPmoPopupColumns:[{ value: 'Y', label: '同意' }, { value: 'N', label: '不同意' }],
      formIndex:0,
      firstCheck:true,
      firstCompanyProvinceCodeName:'',
      firstCompanyCityCodeName:''
    }
  },
  computed: {
    ...mapGetters(['user']),
  },
  props: ['fromdata','todotype','params'],
  watch: {
    fromdata: {
      handler () { //这是vue的规定写法，当你watch的值发生变化的时候，就会触发这个handler，这是vue内部帮你做的事情
        if (this.firstCheck==true){
          this.approvalInfo=this.fromdata.approvalInfo
          if((this.params.location=='dict.provinceJlsqAdminToHq'||this.params.location=='dict.provinceJlsqAdminToHq')&&this.todotype==true){
            this.canSelete=true
          }else {
            this.canSelete=false
          }
          this.setdata()
          this.firstCheck=false
        }
        this.$emit('freshData',this.fromdata)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    }
  },
  methods: {
    showPopupView(index){
      this.isshowPopupView = true;
      this.formIndex = index;
    },
    isPmoClickConfirm(value){
      this.isshowPopupView = false;
      this.fromdata.approvalInfo.incentiveVerifiedInfo[this.formIndex].resultFlag = value.value;
    },
    setdata(){
      // getCountyCode(Object.assign({ userName: this.user.userName }))
      //     .then((result) => {
      //       if (!result.data) {
      //         Notify(result.message);
      //         return;
      //       }
      //       for(var i=0;i<result.data.data.length;i++){
      //         if(result.data.data[i].provinceCode==this.fromdata.solutionIncentiveInfo.afterContractInfos[0].firstCompanyProvinceCode){
      //           this.firstCompanyProvinceCodeName = result.data.data[i].provinceName;
      //         }
      //         if(result.data.data[i].cityCode==this.fromdata.solutionIncentiveInfo.afterContractInfos[0].firstCompanyCityCode){
      //           this.firstCompanyCityCodeName = result.data.data[i].cityName;
      //         }
      //       }
      //     })
      if (this.fromdata?.artificialIncentiveInfo?.nineOneTrackInfo?.nineOneCode){
        getProductNameAndProductCode(Object.assign({ productType: '9One',userName: this.user.userName }))
            .then((result) => {
              if (!result.data) {
                Notify(result.message);
                return;
              }
              for(var i=0;i<result.data.data.length;i++){
                if(this.fromdata.artificialIncentiveInfo.nineOneTrackInfo.nineOneCode.includes(result.data.data[i].VALUE)){
                  if (this.nineOneName==''){
                    this.nineOneName = result.data.data[i].NAME;
                  }else {
                    this.nineOneName = this.nineOneName+','+result.data.data[i].NAME;
                  }
                }
              }
              getProductNameAndProductCode(Object.assign({ productType: '安全',userName: this.user.userName }))
                  .then((result) => {
                    if (!result.data) {
                      Notify(result.message);
                      return;
                    }
                    for(var i=0;i<result.data.data.length;i++){
                      if(this.fromdata.artificialIncentiveInfo.nineOneTrackInfo.nineOneCode.includes(result.data.data[i].VALUE)){
                        if (this.nineOneName==''){
                          this.nineOneName = result.data.data[i].NAME;
                        }else {
                          this.nineOneName = this.nineOneName+','+result.data.data[i].NAME;
                        }
                      }
                    }
                  })
            })
      }
      existArrearsAndRiskWarning(Object.assign({ groupProjectCode: this.fromdata.groupProjectCode,userName: this.user.userName }))
          .then((result) => {
            if (!result.data) {
              Notify(result.message);
              return;
            }
            this.arrearageManagement=result.data.data
          })
    },
    openFileUrlfun(value) {
      this.$router.push(
          {
            name: 'fileview',
            query: {
              openFileUrl: openFileUrl(value)
            }
          }
      );
    },
    file2server(file) {
      let fileData = new FormData();
      fileData.append("pmInsType", this.pmInsType);
      fileData.append("pmInsTypePart", "1");
      fileData.append("files", file.file);

      let params = new Map();
      params.pmInsType = this.pmInsType;
      params.pmInsTypePart = '1';
      params.userName = this.user.userName;
      uploadFileCommon(fileData, params).then((res) => {
        if (!res.data) {
          Notify(res.message);
          return;
        }
        if (res.data.data) {
          if (this.fromdata.makingOpinionsFileList === null) {
            this.fromdata.makingOpinionsFileList = [];
          }
          this.fromdata.makingOpinionsFileList.push(res.data.data.sysFiles[0]);
        }
      });
    },
    deleteFile(index) {
      Dialog.confirm({ title: "提示", message: "是否删除此附件？" })
          .then(() => {
            this.fromdata.opinionFileList.splice(index, 1);
          })
          .catch(() => { });
    },
  },
}
</script>

<style>
.tables.el-table .cell {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 15px;
  padding-left: 5px;
  padding-right: 5px;
}
</style>